package com.zz.service.iml;

import com.zz.dao.OutDao;
import com.zz.dao.PatientDao;
import com.zz.dto.IndexInformation;
import com.zz.dto.SexCount;
import com.zz.pojo.Out;
import com.zz.pojo.Patient;
import com.zz.service.IndexInformationService;
import com.zz.utils.IndexUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.*;

/**
 * Copyright Zz
 * FileName: IndexInformationServiceIml
 * Author:   Zz
 * Date:     2023/6/323:26
 * Description:首页业务层实现类
 * hISTORY:
 * <author>  <time>     <version>    <desc>
 * 作者姓名   修改时间       版本号       描述
 */
@Service
@Transactional
public class IndexInformationServiceIml implements IndexInformationService {
    @Autowired
    private OutDao outDao;
    @Autowired
    private PatientDao patientDao;

    @Override
    public IndexInformation getAllMessage() {
        // 所有的出院信息
        List<Out> outList=outDao.queryOutList();

        // 所有的入院信息
        List<Patient> patientList=patientDao.queryPatientList();

        // 现有病人数
        int patientCount=patientList.size();

        // 入住总人数
        int  okCount= IndexUtil.getOkCount(outList,patientList);

        // 在站男女比例(eg:21:30)
        String peopleCount=IndexUtil.getpeopleCount(patientList);

        // 今日入住人数
        int  inCount=IndexUtil.getInCount(patientList);

        // 累计男女比
        SexCount[] sexd= IndexUtil.getSexd(outList,patientList);

        List<int[]> list=IndexUtil.getBarData(outList,patientList,okCount);

        // 每日新增人数（近7天）
        int[] barData= list.get(0);

        // 每日康复人数（近7天）
        int[] barData2=list.get(1);

        // 每日累计总人数（近7天）
        int[] barData3=list.get(2);

        LocalDate[] category=new LocalDate[7];
        for (int i = 0; i < 7; i++) {
            category[i]=LocalDate.now().minusDays(6-i);
        }
        return new IndexInformation(patientCount,okCount,peopleCount,inCount,sexd,barData,barData2,barData3,category,category,category);
    }
}
